package com.jhxy.algorithm.twosum;

/**
 * 暴力求解:顺序算法
 */
public class TwoSumDeRandom {


    public static void main(String[] args) {

        InputForTwoNumberSum inputs = new InputForTwoNumberSum("2,7,11,15", "26");
        TwoSumDeRandom twoSumDeRandom = new TwoSumDeRandom();
        for (int i : twoSumDeRandom.twoSum(inputs.nums, inputs.target)) {
            System.out.println(i);
        }
    }

    private int[] twoSum(int[] nums, int target) {
        int[] res = new int[2];
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    res[0] = i;
                    res[1] = j;
                    return res;
                }
            }
        }
        return res;
    }
}
